#include<windows.h>
#include<iostream>

using namespace std;


int main(){


	HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS|FILE_MAP_EXECUTE,
						FALSE,
						"MySharedMemory"
						);
	
	
	if(!hMap){
		cerr << "OpenFileMapping failed. Error: "<< GetLastError() << endl;
		
		return 1;
	}
	
	LPVOID pView = MapViewOfFile(hMap,
									FILE_MAP_ALL_ACCESS|FILE_MAP_EXECUTE,
									0,
									0,
									1024);
									
	if(!pView){
		cerr << "MapViewOfFile failed. Error: " << GetLastError() << endl;
		CloseHandle(hMap);
		return 1;
	}
									
	int *p = (int*)pView;
	p[0] = 100;
	p[1] = 200;
	
	cout << "Read shared memory data is :" << endl;
	
	cout << p[0] << endl;
	cout << p[1] << endl;
	cout << p[2] << endl;
	
	UnmapViewOfFile(pView);
	CloseHandle(hMap);
	
	getchar();
	
	cout << "Over!" << endl;
	
	return 0;
}